﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharp1.Core
{
    public class Person
    {
        //自动属性
        public string Name { get; set; }

        public string Sex{get;set;}
        /// <summary>
        /// 字段年龄
        /// </summary>
        private int age;

        /// <summary>
        /// 属性
        /// </summary>
        public int Age
        {
            set
            {
                if (value < 0)
                {
                    age = 0;
                }
                else
                {
                    age = value;
                }
            }
        }


        private int height;
        public int Height
        {
            get // 读取器
            {
                return height;
            }
        }
        /// <summary>
        /// 字段：私有
        /// </summary>
        private int weight;
        /// <summary>
        /// 属性
        /// </summary>
        public int Weight
        {
            set {//给字段赋值
                if (value < 0)//不合法的赋值
                {
                    weight = 0;
                }
                else //合法赋值
                {
                    weight = value;
                }
            }
            get {//返回字段的值
                return weight;
            }
        }

        public void Info()
        {
            Console.WriteLine(@"姓名:{0}
性别:{1}
身高:{2}
体重:{3}", Name, Sex, height, weight);
        }
    }
}
